package com.nit.generate;

import com.nit.tools.loop.NitLoopTools;

/**
 * 颜色色值 生成器
 *
 * @Auth: 逆天开源-逍遥哥哥
 * @link: 1715656022@qq.com
 * @Date: 2023-07-11
 */
public class NitColorGenerator {
    public static void main(String[] args) {
        NitLoopTools.loop(100, () -> {
            String tmp = NitColorGenerator.generate();
            System.out.println("随机色值:" + tmp + "<br>");
        });
    }

    public static String generate() {
        return generateHex();
    }

    /**
     * 随机RGB颜色值
     *
     * @return 随机RGB颜色值
     */
    public static int[] generateRgb() {
        return new int[]{NitNumberGenerator.generateInt(0, 256), NitNumberGenerator.generateInt(0, 256), NitNumberGenerator.generateInt(0, 256)};
    }

    /**
     * 随机HEX颜色值
     *
     * @return 随机HEX颜色值
     */
    public static String generateHex() {
        int[] color = generateRgb();
        return String.format("#%02x%02x%02x", color[0], color[1], color[2]).toUpperCase();
    }
}
